package com.zyy.smartcity1129.me;

import android.view.View;
import android.widget.TextView;

import com.zyy.smartcity1129.BaseFragment;
import com.zyy.smartcity1129.R;
import com.zyy.smartcity1129.data.UserInfo;
import com.zyy.smartcity1129.util.Http;
import com.zyy.smartcity1129.util.XCUtli;

/**
 * @ClassName: MyAccountFragment$
 * @Description: 作用
 * @Author: letquit
 * @CreateDate: 1/12/2021$
 * @Version: 1.0
 */
public class MyAccountFragment extends BaseFragment {
    private TextView textView2;
    private TextView textView3;
    private TextView textView4;
    private TextView textView5;
    private TextView textView6;
    private TextView textView7;
    private TextView textView8;
    private TextView textView9;
    UserInfo.UserBean userBean;

    @Override
    protected int layId() {
        return R.layout.f_account;
    }

    @Override
    protected String title() {
        return "账户";
    }

    @Override
    protected boolean back() {
        return true;
    }

    @Override
    protected Boolean bottom() {
        return null;
    }

    @Override
    protected void init(View iv) {
        initView(iv);
        XCUtli xcUtli = new XCUtli(1);
        xcUtli.then(() -> {
            userBean = Http.getInstance().get("/prod-api/api/common/user/getInfo", null, UserInfo.class, 1).getUser();
            xcUtli.addint();
        });
        xcUtli.XCliveData.observe(getViewLifecycleOwner(), a -> {
            if (a.get() == 1) {
                textView2.setText("用户名：" + userBean.getUserName());
                textView3.setText("用户昵称：" + userBean.getNickName());
                textView4.setText("邮箱：" + userBean.getEmail());
                textView5.setText("手机号：" + userBean.getPhonenumber());
                textView6.setText("用户性别：" + userBean.getSex());
                String idCar = String.valueOf(userBean.getIdCard());
                StringBuffer stringBuffer = new StringBuffer(idCar);
                String str = "";
                for (int i = 0; i < stringBuffer.length() - 6; i++) {
                    str += "*";
                }
                stringBuffer.replace(2, stringBuffer.length() - 4, str);
                textView7.setText("身份证号：" + stringBuffer.toString());
                textView8.setText("账户余额：" + userBean.getBalance());
                textView9.setText("用户积分：" + userBean.getScore());
            }
        });
    }

    private void initView(View iv) {
        textView2 = (TextView) iv.findViewById(R.id.textView2);
        textView3 = (TextView) iv.findViewById(R.id.textView3);
        textView4 = (TextView) iv.findViewById(R.id.textView4);
        textView5 = (TextView) iv.findViewById(R.id.textView5);
        textView6 = (TextView) iv.findViewById(R.id.textView6);
        textView7 = (TextView) iv.findViewById(R.id.textView7);
        textView8 = (TextView) iv.findViewById(R.id.textView8);
        textView9 = (TextView) iv.findViewById(R.id.textView9);
    }
}
